importPackage(net.sf.odinms.net.channel);
importPackage(net.sf.odinms.client);
importPackage(net.sf.odinms.tools);

var status = 0;
var chosen = 0;
var blabla = 0;
var partner = 0;
var ring = Array(1112001, 1112002, 1112003, 1112005, 1112006);
 
function start() {
    status = -1;
    action(1, 0, 0);
}
 
function action(mode, type, selection) {
	if (mode == -1) {
        	cm.dispose();
	} else {
        	if (mode == 0 && status == 0) {
        	cm.dispose();
        	return;
        	}
        	if (mode == 1)
        		status++;
        	else
        		status--;
        	if (status == 0) {
			if (cm.isBlessed() == 1) {
	                	cm.sendNext("Hello #h #, Welcome to #rChickenMS#k\r\nPick the ring you like, ill give it");
			} else {
				cm.sendOk("You need your parents blessing to get a ring");
				cm.dispose();
			}
		} else if (status == 1) {
    			var Selstr = "The available rings are:\r\n(Be aware that you have to pay 1 mil to get connected)\r\n";
			for (var i = 0; i < ring.length; i++) {
				Selstr += "\r\n#L" + i + "##i" + ring[i] + "#";
			}
				cm.sendSimple(Selstr);
		} else if (status == 2) {
			blabla = selection;
			chosen = ring[blabla];
			cm.sendGetText("What is the name of your partner?\r\nMake sure that you spell it right!");
		} else if (status == 3) {
			partner = cm.getText();
			//victim = cm.getPlayer().getClient().getChannelServer().getPlayerStorage().getCharacterByName(cm.getText());
			if (cm.getMeso() >= 1000000) {
				if (cm.itemQuantity(1112001) == 0 && cm.itemQuantity(1112002) == 0 && cm.itemQuantity(1112003) == 0 && cm.itemQuantity(1112005) == 0 && cm.itemQuantity(1112006) == 0 && cm.itemQuantity(1112800) == 0 && cm.itemQuantity(1112801) == 0 && cm.itemQuantity(1112802) == 0) {
					cm.createRing(chosen, cm.getText());
					cm.gainMeso(-1000000);
					cm.dispose();
				} else {
					cm.sendOk("You already have a ring");
					cm.dispose();
				}
			} else {
				cm.sendOk("You dont have enough mesos");
				cm.dispose();
			}
		}	
	}
}